package com.wzw.springboot.principle.use.datasource;


import com.wzw.springboot.principle.transaction.entity.User;
import com.wzw.springboot.principle.transaction.repository.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author Wangzhiwen
 */
@Service
@DatasourceSwitcher(DatasourceEnum.TEACHER)
public class UseService {

    @Resource
    private UserRepository userRepository;

    // @DatasourceSwitcher(DatasourceEnum.USER)
    @Transactional(rollbackFor = Exception.class)
    public void addUser() {
        User user = new User();
        user.setSex("11");
        user.setAge(11);
        userRepository.save(user);
        User user2 = new User();
        user2.setSex("22");
        user2.setAge(22);
        userRepository.save(user2);
    }

}
